package com.achobeta.recruitment.utils;

import com.achobeta.recruitment.model.Message;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 马拉圈
 * Date: 2023-10-31
 * Time: 18:19
 */
public class MessageUtils {


    public static void setTradeInfo(String appId, String secret) {
        String url = "https://api.weixin.qq.com/cgi-bin/template/api_set_industry" + HttpUtils.getQueryString(new HashMap<String, Object>() {{
            this.put("access_token", TokenUtils.getToken(appId, secret));
        }});
        Map<String, Object> param = new HashMap<String, Object>() {{
            this.put("industry_id1", "1");
            this.put("industry_id2", "2");
        }};
        System.out.println(HttpUtils.doPost(url, JsonUtils.objectToJson(param)));
    }
    public static String getTradeInfo(String appId, String secret) {
        String url = "https://api.weixin.qq.com/cgi-bin/template/get_industry" + HttpUtils.getQueryString(new HashMap<String, Object>() {{
            this.put("access_token", TokenUtils.getToken(appId, secret));
        }});
        return HttpUtils.doGet(url, null);
    }

    public static void cutMessage(Message message) {
        String content = message.getContent();
        String title = message.getTitle();
        if(content.length() > 32) {
            message.setContent(content.substring(0, 32) + "...");
        }
        if(title.length() > 32) {
            message.setTitle(title.substring(0, 32) + "...");
        }
    }
}
